home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / disk / diskPrint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-31  |  16.4 KB  |  597 lines

  1. /* 
  2.  * diskPrint.c --
  3.  *
  4.  *    Routines to print out data structures found on the disk.
  5.  *
  6.  * Copyright (C) 1987 Regents of the University of California
  7.  * All rights reserved.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/lib/disk/RCS/diskPrint.c,v 1.8 92/08/31 12:20:44 voelker Exp $ SPRITE (Berkeley)";
  19. #endif not lint
  20.  
  21. #include <stdio.h> 
  22. #include "disk.h"
  23.  
  24.  
  25. /*
  26.  *----------------------------------------------------------------------
  27.  *
  28.  * Disk_PrintDomainHeader --
  29.  *
  30.  *    Print out the domain header.  Used in testing.
  31.  *
  32.  * Results:
  33.  *    None.
  34.  *
  35.  * Side effects:
  36.  *    None.
  37.  *
  38.  *----------------------------------------------------------------------
  39.  */
  40. void
  41. Disk_PrintDomainHeader(headerPtr)
  42.     register Ofs_DomainHeader *headerPtr;/* Reference to domain header to print*/
  43. {
  44.     register Ofs_Geometry *geoPtr;
  45.     register int    index;
  46.  
  47.     printf("Domain Header <%x>\n", headerPtr->magic);
  48.     printf("First Cyl %d, num Cyls %d", headerPtr->firstCylinder,
  49.             headerPtr->numCylinders);
  50.     printf(", raw size %d kbytes\n", headerPtr->numCylinders *
  51.         headerPtr->geometry.sectorsPerTrack *
  52.         headerPtr->geometry.numHeads / 2);
  53.     printf("%-20s %10s %10s\n", "", "offset", "blocks");
  54.     printf("%-20s %10d %10d\n", "FD Bitmap", headerPtr->fdBitmapOffset,
  55.             headerPtr->fdBitmapBlocks);
  56.     printf("%-20s %10d %10d %10d\n", "File Desc", headerPtr->fileDescOffset,
  57.             headerPtr->numFileDesc/FSDM_FILE_DESC_PER_BLOCK,
  58.             headerPtr->numFileDesc);
  59.     printf("%-20s %10d %10d\n", "Bitmap", headerPtr->bitmapOffset,
  60.             headerPtr->bitmapBlocks);
  61.     printf("%-20s %10d %10d\n", "Data Blocks", headerPtr->dataOffset,
  62.             headerPtr->dataBlocks);
  63.     geoPtr = &headerPtr->geometry;
  64.     printf("Geometry\n");
  65.     printf("sectorsPerTrack %d, numHeads %d\n", geoPtr->sectorsPerTrack,
  66.                   geoPtr->numHeads);
  67.     printf("blocksPerRotSet %d, tracksPerRotSet %d\n",
  68.                geoPtr->blocksPerRotSet, geoPtr->tracksPerRotSet);
  69.     printf("rotSetsPerCyl %d, blocksPerCylinder %d\n",
  70.                geoPtr->rotSetsPerCyl, geoPtr->blocksPerCylinder);
  71.     printf("Offset    (Sorted)\n");
  72.     for (index = 0 ; index < geoPtr->blocksPerRotSet ; index++) {
  73.     printf("%8d %8d\n", geoPtr->blockOffset[index],
  74.                geoPtr->sortedOffsets[index]);
  75.     }
  76.  
  77.     printf(">> %d files, %d kbytes\n", headerPtr->numFileDesc,
  78.         headerPtr->dataBlocks * 4);
  79. }
  80.  
  81. /*
  82.  *----------------------------------------------------------------------
  83.  *
  84.  * Disk_PrintSummaryInfo --
  85.  *
  86.  *    Print out the summary information.
  87.  *
  88.  * Results:
  89.  *    None.
  90.  *
  91.  * Side effects:
  92.  *    None.
  93.  *
  94.  *----------------------------------------------------------------------
  95.  */
  96. void
  97. Disk_PrintSummaryInfo(summaryPtr)
  98.     register Ofs_SummaryInfo *summaryPtr; /* Reference to summary info to print */
  99. {
  100.     printf("\"%s\" (%d) \t%d Kbytes free, %d file descriptors free\n",
  101.         summaryPtr->domainPrefix, 
  102.         summaryPtr->domainNumber,
  103.         summaryPtr->numFreeKbytes,
  104.         summaryPtr->numFreeFileDesc);
  105.     printf("Attach seconds: %d\n");
  106.     printf("Detach seconds: %d\n");
  107.     if (summaryPtr->flags & OFS_DOMAIN_NOT_SAFE) {
  108.     printf("OFS_DOMAIN_NOT_SAFE\n");
  109.     }
  110.     if (summaryPtr->flags & OFS_DOMAIN_ATTACHED_CLEAN) {
  111.     printf("OFS_DOMAIN_ATTACHED_CLEAN\n");
  112.     }
  113.     if (summaryPtr->flags & OFS_DOMAIN_TIMES_VALID) {
  114.     printf("OFS_DOMAIN_TIMES_VALID\n");
  115.     }
  116.     if (summaryPtr->flags & OFS_DOMAIN_JUST_CHECKED) {
  117.     printf("OFS_DOMAIN_JUST_CHECKED\n");
  118.     }
  119. }
  120.  
  121. /*
  122.  *----------------------------------------------------------------------
  123.  *
  124.  * Disk_PrintFileDescBitmap --
  125.  *
  126.  *    Print out the file descriptor bitmap.
  127.  *
  128.  * Results:
  129.  *    None.
  130.  *
  131.  * Side effects:
  132.  *    None.
  133.  *
  134.  *----------------------------------------------------------------------
  135.  */
  136. void
  137. Disk_PrintFileDescBitmap(headerPtr, bitmap)
  138.     Ofs_DomainHeader    *headerPtr;    /* Pointer to disk header info. */
  139.     char        *bitmap;    /* Pointer to file desc bit map. */
  140. {
  141.     register int index;
  142.  
  143.     printf("File Descriptor bitmap\n");
  144.     for (index = 0;
  145.      index < headerPtr->fdBitmapBlocks * FS_BLOCK_SIZE;) {
  146.     if ((index % 32) == 0) {
  147.         printf("%6d ", index * BITS_PER_BYTE);
  148.         if (index * BITS_PER_BYTE > headerPtr->numFileDesc) {
  149.         printf(" (The rest of the map is not used)\n");
  150.         break;
  151.         }
  152.     }
  153.     printf("%02x", bitmap[index] & 0xff);
  154.     index++;
  155.     if ((index % 32) == 0) {
  156.         printf("\n");
  157.     }
  158.     }
  159. }
  160.  
  161. /*
  162.  *----------------------------------------------------------------------
  163.  *
  164.  * Disk_PrintDataBlockBitmap --
  165.  *
  166.  *    Print out the data block bitmap.
  167.  *
  168.  * Results:
  169.  *    None.
  170.  *
  171.  * Side effects:
  172.  *    None.
  173.  *
  174.  *----------------------------------------------------------------------
  175.  */
  176. void
  177. Disk_PrintDataBlockBitmap(headerPtr, bitmap)
  178.     Ofs_DomainHeader    *headerPtr;    /* Ptr to disk header info. */
  179.     char        *bitmap;    /* Ptr to data block bit map. */
  180. {
  181.     register int index;
  182.  
  183.     printf("Data block bitmap:\n");
  184.     for (index = 0;
  185.      index < headerPtr->bitmapBlocks * FS_BLOCK_SIZE;) {
  186.     if ((index % 32) == 0) {
  187.         printf("%6d ", index * BITS_PER_BYTE);
  188.         if (index * BITS_PER_BYTE >
  189.         headerPtr->dataBlocks * DISK_KBYTES_PER_BLOCK) {
  190.         printf(" (The rest of the bitmap is not used)\n");
  191.         break;
  192.         }
  193.     }
  194.     printf("%02x", bitmap[index] & 0xff);
  195.     index++;
  196.     if ((index % 32) == 0) {
  197.         printf("\n");
  198.     }
  199.     }
  200. }
  201.  
  202. /*
  203.  *----------------------------------------------------------------------
  204.  *
  205.  * Disk_PrintDirEntry --
  206.  *
  207.  *    Print out one directory entry
  208.  *
  209.  * Results:
  210.  *    None.
  211.  *
  212.  * Side effects:
  213.  *    None.
  214.  *
  215.  *----------------------------------------------------------------------
  216.  */
  217. void
  218. Disk_PrintDirEntry(dirEntryPtr)
  219.     Fslcl_DirEntry *dirEntryPtr;    /* Ptr to directory entry. */
  220. {
  221.     printf("\"%-15s\", File Number = %d, Rec Len = %d, Name Len = %d\n",
  222.            dirEntryPtr->fileName, dirEntryPtr->fileNumber,
  223.            dirEntryPtr->recordLength, dirEntryPtr->nameLength);
  224. }
  225.  
  226. /*
  227.  *----------------------------------------------------------------------
  228.  *
  229.  * Disk_PrintLabel--
  230.  *
  231.  *    Print the contents of a Disk_Label.
  232.  *
  233.  * Results:
  234.  *    None.
  235.  *
  236.  * Side effects:
  237.  *    Stuff is printed.
  238.  *
  239.  *----------------------------------------------------------------------
  240.  */
  241.  
  242. void
  243. Disk_PrintLabel(labelPtr)
  244.     Disk_Label        *labelPtr;    /* Label to be printed.*/
  245. {
  246.     int    i;
  247.     int first, last, cyls;
  248.  
  249.     printf("Ascii label: \"%s\"\n", labelPtr->asciiLabel);
  250.     printf("Length of ascii label: %d\n", labelPtr->asciiLabelLen);
  251.     printf("The disk has a %s label.\n", 
  252.     Disk_GetLabelTypeName(labelPtr->labelType));
  253.     printf("The disk label is in sector %d\n", labelPtr->labelSector);
  254.     printf("Number of heads: %d\n", labelPtr->numHeads);
  255.     printf("Number of sectors per track: %d\n", labelPtr->numSectors);
  256.     printf("Number of cylinders: %d\n", labelPtr->numCylinders);
  257.     printf("Number of alternate cylinders: %d\n", labelPtr->numAltCylinders);
  258.     printf("Starting boot sector: %d\n", labelPtr->bootSector);
  259.     printf("Number of boot sectors: %d\n", labelPtr->numBootSectors);
  260.     printf("Start of summary info: %d\n", labelPtr->summarySector);
  261.     printf("Number of summary sectors: %d\n", labelPtr->numSummarySectors);
  262.     printf("Start of domain header: %d\n", labelPtr->domainSector);
  263.     printf("Number of domain header sectors: %d\n", labelPtr->numDomainSectors);
  264.     printf("Number of disk partitions: %d\n", labelPtr->numPartitions);
  265.     printf("Partition map:\n");
  266.     for (i = 0; i < labelPtr->numPartitions; i++) {
  267.     first = labelPtr->partitions[i].firstCylinder;
  268.     cyls = labelPtr->partitions[i].numCylinders;
  269.     last = (cyls > 0) ? (cyls + first - 1) : first;
  270.     printf("%c: First %4d Last %4d Num %4d (%7d sectors)\n",
  271.         i + 'a', first, last, cyls,
  272.         cyls *  labelPtr->numHeads * labelPtr->numSectors);
  273.     }
  274. }
  275.  
  276. /*
  277.  *----------------------------------------------------------------------
  278.  *
  279.  * Disk_GetLabelTypeName --
  280.  *
  281.  *    Returns a string which is the name of the machine-specific
  282.  *    label type.
  283.  *
  284.  * Results:
  285.  *    Character string name of label type if the type parameter is
  286.  *    valid, NULL otherwise
  287.  *
  288.  * Side effects:
  289.  *    None.
  290.  *
  291.  *----------------------------------------------------------------------
  292.  */
  293.  
  294. char *
  295. Disk_GetLabelTypeName(labelType)
  296.     Disk_NativeLabelType labelType;    /* Type of machine specific label. */
  297. {
  298.     static char *names[3] = {"NO LABEL", "Sun", "Dec"};
  299.  
  300.     if (labelType < 0 || labelType > 2) {
  301.     return NULL;
  302.     }
  303.     return names[labelType];
  304. }
  305.  
  306.  
  307. /*
  308.  *----------------------------------------------------------------------
  309.  *
  310.  * Disk_PrintLfsSuperBlockHdr
  311.  *
  312.  *    Print out the contents of the LFS SuperBlock header
  313.  *
  314.  * Results:
  315.  *    None.
  316.  *
  317.  * Side effects:
  318.  *    Prints stuff to stdout.
  319.  *
  320.  *----------------------------------------------------------------------
  321.  */
  322. void
  323. Disk_PrintLfsSuperBlockHdr(headerPtr)
  324.     LfsSuperBlockHdr *headerPtr;
  325. {
  326.     if (headerPtr == NULL) {
  327.     return;
  328.     }
  329.     printf("LFS SuperBlock magic:                0x%x\n", headerPtr -> magic);
  330.     printf("LFS version:                         %d\n", headerPtr -> version);
  331.     printf("LFS block size in bytes:             %d\n", 
  332.        headerPtr -> blockSize);
  333.     printf("Maximum number of checkpoint blocks: %d\n", 
  334.        headerPtr -> maxCheckPointBlocks);
  335.     printf("Checkpoint #0 offset:                %d\n", 
  336.        headerPtr -> checkPointOffset[0]);
  337.     printf("Checkpoint #1 offset:                %d\n", 
  338.        headerPtr -> checkPointOffset[1]);
  339.     printf("Segemented log offset:               %d\n", 
  340.        headerPtr -> logStartOffset);
  341.     printf("Frequency of checkpoint in seconds:  %d\n",
  342.        headerPtr -> checkpointInterval);
  343.     printf("Maximum number of blocks to clean at one time: %d\n",
  344.        headerPtr -> maxNumCacheBlocks);
  345.     printf("Unique ID for file system:           %d\n",
  346.        headerPtr -> domainUID);
  347.     printf("Partition that the file system was built in: %c\n",
  348.        headerPtr -> partition);
  349. }
  350.  
  351. /*
  352.  *----------------------------------------------------------------------
  353.  *
  354.  * Disk_PrintLfsStableMemParams
  355.  *
  356.  *    Print out the contents of a LFS StableMemParam structure
  357.  *
  358.  * Results:
  359.  *    None.
  360.  *
  361.  * Side effects:
  362.  *    Prints stuff to stdout.
  363.  *
  364.  *----------------------------------------------------------------------
  365.  */
  366. void
  367. Disk_PrintLfsStableMemParams(stableMemPtr)
  368.     LfsStableMemParams *stableMemPtr;
  369. {
  370.     if (stableMemPtr == NULL) {
  371.     return;
  372.     }
  373.     printf("Stable memory type:          %d\n", stableMemPtr -> memType);
  374.     printf("Block size in bytes:         %d\n", stableMemPtr -> blockSize);
  375.     printf("Size of each entry in bytes: %d\n", stableMemPtr -> entrySize);
  376.     printf("Maximum number of entries:   %d\n", stableMemPtr -> maxNumEntries);
  377.     printf("Number of entries per block: %d\n", 
  378.        stableMemPtr -> entriesPerBlock);
  379.     printf("Maximum nmber of blocks:     %d\n", stableMemPtr -> maxNumBlocks);
  380. }
  381.  
  382. /*
  383.  *----------------------------------------------------------------------
  384.  *
  385.  * Disk_PrintLfsDescMapParams
  386.  *
  387.  *    Print out the contents of a LFS DescMapParams structure
  388.  *
  389.  * Results:
  390.  *    None.
  391.  *
  392.  * Side effects:
  393.  *    Prints stuff to stdout.
  394.  *
  395.  *----------------------------------------------------------------------
  396.  */
  397. void
  398. Disk_PrintLfsDescMapParams(descMapPtr)
  399.     LfsDescMapParams *descMapPtr;
  400. {
  401.     if (descMapPtr == NULL) {
  402.     return;
  403.     }
  404.     printf("Version number:                 %d\n", descMapPtr -> version);
  405.     printf("Maximum size in descriptor map: %d\n\n", descMapPtr -> maxDesc);
  406.     printf("Index Parameters for the descriptor map:\n");
  407.     Disk_PrintLfsStableMemParams(&(descMapPtr -> stableMem));
  408. }
  409.  
  410. /*
  411.  *----------------------------------------------------------------------
  412.  *
  413.  * Disk_PrintLfsSegUsageParams
  414.  *
  415.  *    Print out the contents of a LFS SegUsageParams structure
  416.  *
  417.  * Results:
  418.  *    None.
  419.  *
  420.  * Side effects:
  421.  *    Prints stuff to stdout.
  422.  *
  423.  *----------------------------------------------------------------------
  424.  */
  425. void
  426. Disk_PrintLfsSegUsageParams(segUsagePtr)
  427.     LfsSegUsageParams *segUsagePtr;
  428. {
  429.     if (segUsagePtr == NULL) {
  430.     return;
  431.     }
  432.     printf("Number of bytes in each segment:            %d\n", 
  433.        segUsagePtr -> segmentSize);
  434.     printf("Number of segments in file system:          %d\n", 
  435.        segUsagePtr -> numberSegments);
  436.     printf("Minimum number of clean segments allowed:   %d\n", 
  437.        segUsagePtr -> minNumClean);
  438.     printf("Minimum number of free blocks allowed:      %d\n", 
  439.        segUsagePtr -> minFreeBlocks);
  440.     printf("Number of allowed waste blocks per segment: %d\n", 
  441.        segUsagePtr -> wasteBlocks);
  442.     printf("Number of segments to clean at a time:      %d\n\n", 
  443.        segUsagePtr -> numSegsToClean);
  444.     printf("Index Parameters for the Segment Usage Map:\n");
  445.     Disk_PrintLfsStableMemParams(&(segUsagePtr -> stableMem));
  446. }
  447.  
  448. /*
  449.  *----------------------------------------------------------------------
  450.  *
  451.  * Disk_PrintLfsFileLayoutParams
  452.  *
  453.  *    Print out the contents of a LFS FileLayoutParams structure
  454.  *
  455.  * Results:
  456.  *    None.
  457.  *
  458.  * Side effects:
  459.  *    Prints stuff to stdout.
  460.  *
  461.  *----------------------------------------------------------------------
  462.  */
  463. void
  464. Disk_PrintLfsFileLayoutParams(fileLayoutPtr)
  465.     LfsFileLayoutParams *fileLayoutPtr;
  466. {
  467.     if (fileLayoutPtr == NULL) {
  468.     return;
  469.     }
  470.     printf("Number of file descriptors to pack per block: %d\n",
  471.        fileLayoutPtr -> descPerBlock);
  472. }
  473.  
  474. /*
  475.  *----------------------------------------------------------------------
  476.  *
  477.  * Disk_PrintLfsSuperBlock
  478.  *
  479.  *    Print out the contents of a LFS SuperBlock
  480.  *
  481.  * Results:
  482.  *    None.
  483.  *
  484.  * Side effects:
  485.  *    Prints stuff to stdout.
  486.  *
  487.  *----------------------------------------------------------------------
  488.  */
  489. void
  490. Disk_PrintLfsSuperBlock(superPtr)
  491.     LfsSuperBlock *superPtr;
  492. {
  493.     if (superPtr == NULL) {
  494.     return;
  495.     }
  496.     printf("SuperBlock Header:\n");
  497.     Disk_PrintLfsSuperBlockHdr(&(superPtr -> hdr));
  498.     printf("\nDescriptor Map Parameters:\n");
  499.     Disk_PrintLfsDescMapParams(&(superPtr -> descMap));
  500.     printf("\nSegment Usage Map Parameters:\n");
  501.     Disk_PrintLfsSegUsageParams(&(superPtr -> usageArray));
  502.     printf("\nFile Layout Parameters:\n");
  503.     Disk_PrintLfsFileLayoutParams(&(superPtr -> fileLayout));
  504. }
  505.  
  506. /*
  507.  *----------------------------------------------------------------------
  508.  *
  509.  * Disk_PrintLfsCheckPointHdr
  510.  *
  511.  *    Print out the contents of a LFS CheckPointHdr
  512.  *
  513.  * Results:
  514.  *    None.
  515.  *
  516.  * Side effects:
  517.  *    Prints stuff to stdout.
  518.  *
  519.  *----------------------------------------------------------------------
  520.  */
  521. void
  522. Disk_PrintLfsCheckPointHdr(headerPtr)
  523.     LfsCheckPointHdr *headerPtr;
  524. {
  525.     if (headerPtr == NULL) {
  526.     return;
  527.     }
  528.     printf("Timestamp of the checkpoint:      %d\n", headerPtr -> timestamp);
  529.     printf("Size of the checkpoint in bytes:  %d\n", headerPtr -> size);
  530.     printf("Region write version number:      %d\n", headerPtr -> version);
  531.     printf("Last prefix used for this domain: %s\n", headerPtr -> 
  532.        domainPrefix);
  533.     printf("Last domain run under:            %d\n", headerPtr -> 
  534.        domainNumber);
  535.     printf("Time the disk was attached:       %d\n", headerPtr -> 
  536.        attachSeconds);
  537.     printf("Time the disk was off-lined:      %d\n", headerPtr -> 
  538.        detachSeconds);
  539.     printf("Sprite ID of server:              %d\n", headerPtr -> serverID);
  540. }
  541.  
  542. /*
  543.  *----------------------------------------------------------------------
  544.  *
  545.  * Disk_PrintLfsCheckPointRegion
  546.  *
  547.  *    Print out the contents of a LFS CheckPointRegion
  548.  *
  549.  * Results:
  550.  *    None.
  551.  *
  552.  * Side effects:
  553.  *    Prints stuff to stdout.
  554.  *
  555.  *----------------------------------------------------------------------
  556.  */
  557. void
  558. Disk_PrintLfsCheckPointRegion(regionPtr)
  559.     LfsCheckPointRegion *regionPtr;
  560. {
  561.     if (regionPtr == NULL) {
  562.     return;
  563.     }
  564.     printf("Region type:             %s\n", 
  565.        (regionPtr -> type == LFS_FILE_LAYOUT_MOD) ? "LFS_FILE_LAYOUT_MOD" :
  566.        ((regionPtr -> type == LFS_DESC_MAP_MOD) ? "LFS_DESC_MAP_MOD" :
  567.        "LFS_SEG_USAGE_MOD"));
  568.     printf("Size of region in bytes: %d\n", regionPtr -> size);
  569. }
  570.  
  571. /*
  572.  *----------------------------------------------------------------------
  573.  *
  574.  * Disk_PrintLfsCheckPointTrailer
  575.  *
  576.  *    Print out the contents of a LFS CheckPointTrailer
  577.  *
  578.  * Results:
  579.  *    None.
  580.  *
  581.  * Side effects:
  582.  *    Prints stuff to stdout.
  583.  *
  584.  *----------------------------------------------------------------------
  585.  */
  586. void
  587. Disk_PrintLfsCheckPointTrailer(trailerPtr)
  588.     LfsCheckPointTrailer *trailerPtr;
  589. {
  590.     if (trailerPtr == NULL) {
  591.     return;
  592.     }
  593.     printf("Timestamp of the checkpoint: %d\n", trailerPtr -> timestamp);
  594.     printf("Checksum of the checkpoint:  %d\n", trailerPtr -> checkSum);
  595. }
  596.  
  597.